<?php

# 
# Copyright (c) 2002-2007 Eric Wallengren
# This file is part of the Continuous Automated Build and Integration 
# Environment (CABIE)
# 
# CABIE is distributed under the terms of the GNU General Public
# License version 2 or any later version.  See the file COPYING for copying 
# permission or http://www.gnu.org. 
#                                                                            
# THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED OR  
# IMPLIED, without even the implied warranty of MERCHANTABILITY or FITNESS 
# FOR A PARTICULAR PURPOSE.  ANY USE IS AT YOUR OWN RISK. 
#                                                                            
# Permission to modify the code and to distribute modified code is granted, 
# provided the above notices are retained, and a notice that the code was 
# modified is included with the above copyright notice. 
# 

    // Define admin command structure

    class cmddefs {

        function __construct($request) {

            $this->server    = $request['server'];
            $this->port      = $request['port'];
            $this->jobname   = $request['jobname'];
            $this->jobno     = $request['jobno'];
            $this->comment   = $request['comment'];
            $this->newjob    = $request['newjob'];
            $this->buildtype = $request['buildtype'];
            $this->who       = $request['who'];
            $this->pid       = $request['pid'];

            $jobarg = (isset($this->jobno)) ? '-j '.$this->jobno : '';

            $this->admincmds = array(

                "promote" => array(
                    "server"  => $this->server,
                    "port"    => $this->port,
                    "level"   => 2,
                    "args"    => '-n '.$this->jobname.' '.
                                 '-j '.$this->jobno.' '.
                                 '-c promoted_by_'.$this->who
                ),
                "dumpconfig" => array(
                    "server"  => $this->server,
                    "port"    => $this->port,
                    "level"   => 99,
                    "dotable" => 1,
                    "title"   => "server configuration settings",
                    "header"  => "<tr>\n".
                                 "<td class='colnames' align=left width=100<b>".
                                 "name</b></td>\n".
                                 "<td class='colnames' align=left width=100<b>".
                                 "value</b></td>\n".
                                 "</tr>\n",
                    "cols"    => 2,
                    "class"   => 'values',
                    "args"    => '-w'
                ),
                "enable"  => array(
                    "server"  => $this->server,
                    "port"    => $this->port,
                    "level"   => 50,
                    "args"    => '-n '.$this->jobname
                ),
                "disable"  => array(
                    "server"  => $this->server,
                    "port"    => $this->port,
                    "level"   => 50,
                    "args"    => '-n '.$this->jobname
                ),
                "build"   => array(
                    "server"  => $this->server,
                    "port"    => $this->port,
                    "level"   => 50,
                    "args"    => '-n '.$this->jobname
                ),
                "clone"   => array(
                    "server"  => $this->server,
                    "port"    => $this->port,
                    "level"   => 99,
                    "args"    => '-n '.$this->jobname.' '.
                                 '-c '.$this->newjob
                ),
                "kill"    => array(
                    "server"  => $this->server,
                    "port"    => $this->port,
                    "level"   => 50,
                    "args"    => '-p '.$this->pid.' '.
                                 '-s 9'
                ),
                "restorejob"  => array(
                    "server"  => $this->server,
                    "port"    => $this->port,
                    "level"   => 99,
                    "args"    => '-n '.$this->jobname
                ),
                "removejob"  => array(
                    "server"  => $this->server,
                    "port"    => $this->port,
                    "level"   => 99,
                    "args"    => '-n '.$this->jobname
                ),
                "shutdown"    => array(
                    "server"  => $this->server,
                    "port"    => $this->port,
                    "level"   => 99,
                    "args"    => ''
                ),
                "login"   => array(
                    "level"  => 0,
                    "intern" => 1
                ),
                "logout"   => array(
                    "level"  => 0,
                    "intern" => 1
                ),
                "deletejob"     => array(
                    "server"  => $this->server,
                    "port"    => $this->port,
                    "level"   => 99,
                    "alt"     => 'removejob',
                    "args"    => '-n '.$this->jobname.' '.
                                 '-f'
                ),
                "killjob"     => array(
                    "server"  => $this->server,
                    "port"    => $this->port,
                    "level"   => 50,
                    "chain"   => 'disable',
                    "alt"     => 'enable',
                    "args"    => '-n '.$this->jobname.' '.
                                 '-f -k'
                )

            );

            $this->usercmds = array(

                "servers"    => array(
                    "server"  => $this->server,
                    "port"    => $this->port,
                    "level"   => 0,
                    "title"   => "known buildservers",
                    "header"  => "<tr>\n".
                                 "<td class='colnames' align=left width=100<b>".
                                 "name</b></td>\n".
                                 "<td class='colnames' align=left width=100<b>".
                                 "port</b></td>\n".
                                 "<td class='colnames' align=left width=100<b>".
                                 "status</b></td>\n".
                                 "<td class='colnames' align=left width=100<b>".
                                 "description</b></td>\n".
                                 "</tr>\n",
                    "cols"    => 4,
                    "class"   => 'values',
                    "args"    => '-w'
                ),
                "changed"     => array(
                    "server"  => $this->server,
                    "port"    => $this->port,
                    "title"   => $this->jobname." ".$this->jobno." ".
                                 "change information",
                    "level"   => 0,
                    "header"  => "<tr>\n".
                                 "<td class='colnames' align=left width=100<b>".
                                 "job</b></td>\n".
                                 "<td class='colnames' align=left width=100<b>".
                                 "user</b></td>\n".
                                 "<td class='colnames' align=left width=100<b>".
                                 "version</b></td>\n".
                                 "<td class='colnames' align=left width=100<b>".
                                 "filename</b></td>\n".
                                 "</tr>\n",
                    "cols"    => 4,
                    "class"   => 'values',
                    "args"    => '-n '.$this->jobname.' '.
                                 '-j '.$this->jobno.' '.
                                 '-w'
                ),
                "describe"    => array(
                    "server"  => $this->server,
                    "port"    => $this->port,
                    "title"   => $this->jobname." job information",
                    "level"   => 0,
                    "header"  => "<tr>\n".
                                 "<td class='colnames' align=left width=100<b>".
                                 "sccs</b></td>\n".
                                 "<td class='colnames' align=left width=100<b>".
                                 "client</b></td>\n".
                                 "<td class='colnames' align=left width=100<b>".
                                 "port</b></td>\n".
                                 "<td class='colnames' align=left width=100<b>".
                                 "root</b></td>\n".
                                 "<td class='colnames' align=left width=100<b>".
                                 "keep</b></td>\n".
                                 "<td class='colnames' align=left width=100<b>".
                                 "last good</b></td>\n".
                                 "<td class='colnames' align=left width=100<b>".
                                 "comment</b></td>\n".
                                 "</tr>\n",
                    "cols"    => 7,
                    "class"   => 'values',
                    "args"    => '-n '.$this->jobname.' '.
                                 '-w'
                ),
                "teststatus"  => array(
                    "server"  => $this->server,
                    "port"    => $this->port,
                    "title"   => $this->jobname." ".$this->jobno." ".
                                 "test information",
                    "level"   => 0,
                    "header"  => "<tr>\n".
                                 "<td class='colnames' align=left width=100<b>".
                                 "name</b></td>\n".
                                 "<td class='colnames' align=left width=100<b>".
                                 "job</b></td>\n".
                                 "<td class='colnames' align=left width=100<b>".
                                 "testname</b></td>\n".
                                 "<td class='colnames' align=left width=100<b>".
                                 "os</b></td>\n".
                                 "<td class='colnames' align=left width=100<b>".
                                 "server</b></td>\n".
                                 "<td class='colnames' align=left width=100<b>".
                                 "state</b></td>\n".
                                 "</tr>\n",
                    "cols"    => 6,
                    "class"   => 'values',
                    "args"    => '-n '.$this->jobname.' '.
                                 '-w '.
                                 "$jobarg"
                ),
                "removed"  => array(
                    "server"  => $this->server,
                    "port"    => $this->port,
                    "level"   => 0,
                    "title"   => "removed jobs",
                    "header"  => "<tr>\n".
                                 "    <td class=regvalues>\n",
                    "footer"  => "    </td>\n".
                                 "</tr>\n",
                    "cols"    => 1,
                    "class"   => 'values',
                    "args"    => '-w'
                ),
                "nextjob"     => array(
                    "server"  => $this->server,
                    "port"    => $this->port,
                    "level"   => 0,
                    "title"   => "pending changes for ".
                                 $this->jobname,
                    "header"  => "<tr>\n".
                                 "    <td class=regvalues>\n",
                    "footer"  => "    </td>\n".
                                 "</tr>\n",
                    "cols"    => 1,
                    "class"   => 'values',
                    "pre"     => 1,
                    "args"    => '-n '.$this->jobname
                ),
                "lastchange"  => array(
                    "server"  => $this->server,
                    "port"    => $this->port,
                    "level"   => 0,
                    "title"   => "last change submitted for ".
                                 $this->jobname,
                    "header"  => "<tr>\n".
                                 "    <td class=regvalues>\n",
                    "footer"  => "    </td>\n".
                                 "</tr>\n",
                    "cols"    => 1,
                    "class"   => 'values',
                    "pre"     => 1,
                    "args"    => '-n '.$this->jobname.' '.
                                 '-w'
                ),
                "sysinfo"  => array(
                    "server"  => $this->server,
                    "port"    => $this->port,
                    "level"   => 0,
                    "title"   => "operating system information",
                    "header"  => "<tr>\n".
                                 "    <td class=regvalues>\n",
                    "footer"  => "    </td>\n".
                                 "</tr>\n",
                    "cols"    => 1,
                    "class"   => 'values',
                    "pre"     => 1,
                    "args"    => ''
                ),
                "runstats" => array(
                    "server"  => $this->server,
                    "port"    => $this->port,
                    "level"   => 0,
                    "args"    => '-n '.$this->jobname
                ),
                "debuglog" => array(
                    "server"  => $this->server,
                    "port"    => $this->port,
                    "title"   => $this->jobname." debug information",
                    "level"   => 0,
                    "header"  => "<tr>\n".
                                 "<td class='colnames' align=left width=100>".
                                 "<b>".
                                 "debug log</b></td>\n".
                                 "</tr>\n".
                                 "<tr>\n".
                                 "    <td class=values>\n",
                    "footer"  => "    </td>\n".
                                 "</tr>\n",
                    "cols"    => 1,
                    "pre"     => 1,
                    "class"   => 'values',
                    "args"    => '-n '.$this->jobname
                ),
                "buildlog" => array(
                    "server"  => $this->server,
                    "port"    => $this->port,
                    "title"   => $this->jobname." running buildlog",
                    "level"   => 0,
                    "header"  => "<tr>\n".
                                 "<td class='colnames' align=left width=100>".
                                 "<b>".
                                 "activity</b></td>\n".
                                 "</tr>\n".
                                 "<tr>\n".
                                 "    <td class=values>\n",
                    "footer"  => "    </td>\n".
                                 "</tr>\n",
                    "cols"    => 1,
                    "class"   => 'values',
                    "args"    => '-n '.$this->jobname.' '.
                                 '-t '.$this->buildtype.' '.
                                 '-w'
                ),
               "instructions" => array(
                    "server"  => $this->server,
                    "port"    => $this->port,
                    "title"   => $this->jobname." job information",
                    "level"   => 0,
                    "header"  => "<tr>\n".
                                 "<td class='colnames' align=left width=100<b>".
                                 "build instructions</b></td>\n".
                                 "</tr>\n".
                                 "<tr>\n".
                                 "    <td class=regvalues>\n",
                    "footer"  => "    </td>\n".
                                 "</tr>\n",
                    "chain"   => "describe",
                    "cols"    => 1,
                    "pre"     => 1,
                    "class"   => "values",
                    "args"    => '-n '.$this->jobname
                ),
                "set"      => array(
                    "server"  => $this->server,
                    "port"    => $this->port,
                    "title"   => "environment settings",
                    "level"   => 0,
                    "header"  => "<tr>\n".
                                 "<td class='colnames' align=left width=100<b>".
                                 "name</b></td>\n".
                                 "<td class='colnames' align=left width=100<b>".
                                 "value</b></td>\n".
                                 "</tr>\n",
                    "cols"    => 2,
                    "class"   => 'values',
                    "args"    => '-w'
                ),
                "viewusers" => array(
                    "server"  => $this->server,
                    "title"   => "authorized users",
                    "level"   => 1,
                    "header"  => "<tr>\n".
                                 "<td class='colnames' align=left width=100<b>".
                                 "name</b></td>\n".
                                 "<td class='colnames' align=left width=100<b>".
                                 "user realm</b></td>\n".
                                 "<td class='colnames' align=left width=100<b>".
                                 "realm id</b></td>\n".
                                 "</tr>\n",
                    "cols"    => 3,
                    "func"    => 'displayusers',
                    "class"   => 'values'
                ),
                "ps"       => array(
                    "server"  => $this->server,
                    "port"    => $this->port,
                    "title"   => "process table",
                    "level"   => 0,
                    "header"  => "<tr>\n".
                                 "<td class='colnames' align=left width=100<b>".
                                 "user</b></td>\n".
                                 "<td class='colnames' align=left width=100<b>".
                                 "pid</b></td>\n".
                                 "<td class='colnames' align=left width=100<b>".
                                 "ppid</b></td>\n".
                                 "<td class='colnames' align=left width=100<b>".
                                 "cpu</b></td>\n".
                                 "<td class='colnames' align=left width=100<b>".
                                 "stime</b></td>\n".
                                 "<td class='colnames' align=left width=100<b>".
                                 "tty</b></td>\n".
                                 "<td class='colnames' align=left width=100<b>".
                                 "time</b></td>\n".
                                 "<td class='colnames' align=left width=100<b>".
                                 "cmd</b></td>\n".
                                 "</tr>\n",
                    "cols"    => 8,
                    "class"   => 'values',
                    "args"    => '-w'
                )
            );
    
        }

        function _returnadmincmd($command) {

            $cmdarray = $this->admincmds["$command"];

            return $cmdarray;

        }

        function _returnusercmd($command) {

            $cmdarray = $this->usercmds["$command"];

            return $cmdarray;

        }

        function __destruct(){}

    }

?>
